﻿#ifndef __SS_MYSQL_STMT_QUERY_H__
#define __SS_MYSQL_STMT_QUERY_H__
#include "./ssMySQLConnection.h"
#include "./ssMySQLStmt.h"
#include <map>


namespace StarSeeker
{
class ssMySQLStmtQuery : public ssMySQLConnection
{
public:
	ssMySQLStmtQuery();
	~ssMySQLStmtQuery();
	//结束连接
	void StmtExit();
	//查询
	int Query(const char* pSql, const char* pIn, const char* pOut, u8 resultFlag, i32 num, ...);
	int QueryStreaming(const char* pSql, const char* pIn, const char* pOut, u8 resultFlag, u32 len, const char* data);
	//获取结果
	std::pair<int, ssLineBuffer&> GetResultSet();
	std::pair<int, ssReadBytes> GetOneResult();
	int GetOneResult(ssReadBytes& rb);
	//预处理
	int PrepareQuery(u32 id, const char* pIn, const char* pOut, const char* pSql, const u8 resultFlag);
	//预处理
	//insert into table(a,b,c,d) values(${i8},${i8},${i8},${i8})
	//select #{i8,a},#{i8,b} from table where c=${i8}
	//@{i8,i8} call function(${i8},${i8},${i8},${i8})
	//$输入符号  #输出符号  @函数返回符号   @和#不能共存
	int PrepareQuery(u32 id, const char* pSql, const u8 resultFlag);
	//自动查询
	int QueryByID(u32 id, i32 num, ...);
	int QueryByIDStreaming(u32 id, u32 len, const char* data);
	//获取结果
	std::pair<int, ssLineBuffer&> GetResultSet(u32 id);
	std::pair<int, ssReadBytes> GetOneResult(u32 id);
	int GetOneResult(u32 id, ssReadBytes& rb);
	//获取查询类型
	u8 GetResultFlag(u32 id);
private:
	//重新预处理
	void RePrepare();
private:
	ssMySQLStmt					m_stmt;
	std::map<u32, ssMySQLStmt>	m_stmtMap;
};

}
#endif
